package top.goldenyear.porpoise.system.permission.controller.admin;

import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.*;
import top.goldenyear.porpoise.common.core.model.Ret;
import top.goldenyear.porpoise.framework.web.core.controller.BaseController;
import top.goldenyear.porpoise.framework.web.core.model.query.QPage;
import top.goldenyear.porpoise.system.permission.model.Permission;
import top.goldenyear.porpoise.system.permission.service.PermissionService;

/**
 * 菜单权限表 Controller 控制层
 *
 * @author airhead
 * @since 2024-10-17
 */
@Component(tag = "adminApi")
@Mapping("/permission")
@Slf4j
public class PermissionAdminController extends BaseController {
  @Inject private PermissionService service;

  @Post
  @Mapping("/menu/create")
  public Ret create(@Body Permission permission) {
    return Ret.okWithData(service.createMenu(permission));
  }

  @Post
  @Put
  @Mapping("/menu/update")
  public Ret update(@Body Permission permission) {
    return Ret.okWithData(service.updateMenu(permission));
  }

  @Get
  @Mapping("/menu/get")
  public Ret get(@Param Integer id) {
    return Ret.okWithData(service.getMenu(id));
  }

  @Post
  @Delete
  @Mapping("/menu/delete")
  public Ret delete(@Param Integer id) {
    return Ret.okWithData(service.deleteMenu(id));
  }

  @Get
  @Mapping("/menu/paginate")
  public Ret paginate(QPage qPage) {
    Permission permission = getBean(Permission.class);
    return Ret.okWithData(service.paginateMenu(qPage, permission));
  }

  @Get
  @Mapping("/menu/list")
  public Ret list() {
    Permission permission = getBean(Permission.class);
    return Ret.okWithData(service.listMenu(permission));
  }

  @Get
  @Mapping("/menu/tree")
  public Ret tree(List<Integer> types) {
    return Ret.okWithData(service.treeMenu(types));
  }

  @Post
  @Mapping("/button/create")
  public Ret createButton(@Body Permission permission) {
    return Ret.okWithData(service.createButton(permission));
  }

  @Post
  @Put
  @Mapping("/button/update")
  public Ret updateButton(@Body Permission permission) {
    return Ret.okWithData(service.updateButton(permission));
  }

  @Get
  @Mapping("/button/get")
  public Ret getButton(@Param Integer id) {
    return Ret.okWithData(service.getButton(id));
  }

  @Post
  @Delete
  @Mapping("/button/delete")
  public Ret deleteButton(@Param Integer id) {
    return Ret.okWithData(service.deleteButton(id));
  }

  @Get
  @Mapping("/button/paginate")
  public Ret paginateButton(QPage qPage) {
    Permission permission = getBean(Permission.class);
    return Ret.okWithData(service.paginateButton(qPage, permission));
  }

  @Get
  @Mapping("/button/list")
  public Ret listButton() {
    Permission permission = getBean(Permission.class);
    return Ret.okWithData(service.listButton(permission));
  }

  @Get
  @Mapping("getMenuTree")
  public Ret getMenuTree() {
    return Ret.okWithData(service.getMenuTree());
  }

  @Get
  @Mapping("getAllPages")
  public Ret getAllPages() {
    return Ret.okWithData(service.getAllPages());
  }
}
